import moment from 'moment'
export function exceDataCheck(res) {
    // 定义check项目
    let personNameCheckFlg = true
    let personNameCheckColumn = []
    let idNoCheckFlg = true
    let idNoCheckColumn = []
    let phoneCheckFlg = true
    let phoneCheckColumn = []
    let arr = []
    reg = /^\d{0,16}$/,

        res.forEach((val, index) => {
            val.服务开始时间 = typeof (val.服务开始时间) === 'number' ? val.服务开始时间.toString() : val.服务开始时间;



            if (val.激励对象姓名 === undefined || val.激励对象姓名 === '') {
                personNameCheckFlg = false
                personNameCheckColumn.push(index + 3)
            }
            if (val.身份证号 === undefined || val.身份证号 === '') {
                idNoCheckFlg = false
                idNoCheckColumn.push(index + 3)
            }
            if (val.联系电话 === undefined || val.联系电话 === '') {
                phoneCheckFlg = false
                phoneCheckColumn.push(index + 3)
            } else if (!reg.test(val.联系电话)) {
                phoneCheckFlg = 'error'
                phoneCheckColumn.push(index + 3)
            }

            arr.push({
                personName: val.激励对象姓名,
                idNumber: val.身份证号
            })
        });
    let message = ''
    if (arr.length == 0) {
        message = '导入模板数据为空'
    } else if (!personNameCheckFlg) {
        message = formatMessage(personNameCheckColumn, 1, "(激励对象姓名)", "内容存在为空")
    } else if (idNoCheckFlg) {
        message = formatMessage(idNoCheckColumn, 2, "(身份证号)", "内容存在为空")
    } else if (!phoneCheckFlg) {
        message = formatMessage(phoneCheckColumn, 9, "(联系电话)", "内容存在为空")
    } else if (phoneCheckFlg === 'error') {
        message = formatMessage(phoneCheckColumn, 10, "(联系电话)", "格式错误")
    }

    // 设置返回值
    let result = { checkFlg: true, message: "", arr: [] }
    if (message != "") {
        result.checkFlg = false
        result.message = message
    }
    result.arr = arr

    return result

}

function formatMessage(row, column, title, message) {
    return "第" + row + "行 第" + column + "列" + title + "" + message
}